﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工资明细管理</title>
    <#include "../common/link.ftl">

    <script>
        $(function () {
            $('.btn-input').click(function () {
                //清除模态框中旧有的数据
                $('#editForm')[0].reset();//DOM特有的方法
                $('input[name=id]').val('');

                console.log(this);
                //获取编辑时的按钮数据
                var data = $(this).data('json');
                //使用DOM操作渲染模态框
                if (data) {
                    $('input[name=id]').val(data.id);
                    $('input[name=year]').val(data.year);
                    $('input[name=month]').val(data.month);
                    $('input[name=money]').val(data.money);
                    $('select[name="employee.id"]').val(data.employeeId);
                    $('select[name="systemDictionaryItem.id"]').val(data.payoutId);
                }
                $('#editModal').modal('show');
            });


            //当点击保存
            $('.btn-submit').click(function () {
                //只有是在form表单里才可以使用jQuery form
                $('#editForm').ajaxSubmit(function (data) {
                    if (data.success) {
                        $.messager.confirm("提示", data.msg, function () {
                            location.reload();
                        });
                    } else {
                        $.messager.alert(data.msg);
                    }
                });
            });

            //防止潘页的时候数据丢失
            $('li.employee').click(function () {
                console.log(this);
                //获取字典目录id
                var parentId = $(this).attr('data-id');
                console.log(parentId);
                //查询表单隐藏的input,把数据字典目录id的值设置到input value上
                $('#parentId').val(parentId);
                $('#searchForm').submit();
            });

            //获取被选中的目录
            var $li = $('#employees>li.active');
            if ($li) {
                var id = $li.attr('data-id');
                var title = $li.html();
                /*console.log(title);*/
                var $option = $('select[name=parentId]').find('option');
                $option.val(id);
                $option.html(title);
            }
        });
    </script>


</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
     <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="salary">
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>工资管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row">
                    <div class="col-md-3">
                        <ul class="list-group" id="employees">
                            <#list employees as employee>
                                <li class="list-group-item employee ${(employee.id==(qo.parentId)!-1)?string('active','')}"
                                    data-id="${employee.id}">${employee.name}</li>
                            </#list>
                        </ul>
                    </div>
                    <div class="col-md-9">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/salary/list.do" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="parentId" id="parentId" value="${(qo.parentId)!}">
                            <#if  qo.parentId??>
                                 <a class="btn btn-success btn-input" style="margin: 10px">
                                     <span class="glyphicon glyphicon-plus"></span> 添加
                                 </a>
                            </#if>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>年份</th>
                                    <th>月份</th>
                                    <th>员工</th>
                                    <th>工资</th>
                                    <th>发放方式</th>
                                    <th>操作</th>
                                </tr>
                        <#list result.list as info>
                            <tr>
                                <td>${info_index+1}</td>
                                <td>${info.year!}</td>
                                <td>${info.month!}</td>
                                <td>${(info.employee.name)!}</td>
                                <td>${info.money!}</td>
                                <td>${(info.systemDictionaryItem.title!)}</td>
                                <td>

                                <a data-json='${info.jsonData}' class="btn btn-info btn-xs btn-input">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                                </td>
                            </tr>
                        </#list>
                            </table>
                            <!--分页-->
                    <#include "../common/page.ftl">
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>


<!---字典目录编辑--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">工资管理</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/salary/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">年份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="year" value="${result.year!}" placeholder="年份">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">月份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="month" value="${result.month!}" placeholder="月份">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">员工：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="employeeId" name="employee.id" readonly>
                                 <#list employees as e>
                                     <option value="${e.id}">${e.name}</option>
                                 </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">工资：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="money" value="${result.money!}" placeholder="工资">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">发放方式：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="systemDictionaryItemId" name="systemDictionaryItem.id" readonly>
                                <#list systemDictionaryItems as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-submit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>

